#include "type.h"
#include "const.h"
#include "protect.h"
#include "console.h"
#include "tty.h"
#include "string.h"
#include "proc.h"
#include "global.h"
#include "proto.h"

/*----------------------------------------------------
函数名：itoa
作用：  将数转化为字符
------------------------------------------------------*/
PUBLIC char* itoa(char * str, int num)
{
	char *p = str;
	char ch;
	int	i;
	t_bool flag = FALSE;

	*p++ = '0';
	*p++ = 'x';

	if(num == 0){
		*p++ = '0';
	}
	else{	
		for(i = 28;i >= 0;i -= 4){
			ch = (num >> i) & 0xF;
			if(flag || (ch > 0)){
				flag = TRUE;
				ch += '0';
				if(ch > '9'){
					ch += 7;
				}
				*p++ = ch;
			}
		}
	}

	*p = 0;

	return str;
}

/*----------------------------------------------------
函数名：disp_int
作用：  32位数值用 16 进制显示
------------------------------------------------------*/
PUBLIC void disp_int(int input)
{
	char output[16];
	itoa(output, input);
	disp_str(output);
}

/*----------------------------------------------------
函数名：delay
作用：  延时一点时间
------------------------------------------------------*/
PUBLIC void delay(int time)
{
	int i, j, k;
	for (k = 0; k < time; k++) {
		for (i = 0; i < 1000; i++) {
			for (j = 0; j < 1000; j++) {}
		}
	}
}